#pragma strict
var targetPie : GameObject;

var blackberries : int;
var total : int;
var blackberriesToDisplay : int;
var totalToDisplay : int;
var divisor : int;

var isTotal : boolean;

private var targetScript : TargetPieScript;

function Start () {

	targetScript = targetPie.gameObject.GetComponent("TargetPieScript");
	divisor = 1;
}

function Update () {
	
	if (!isTotal) {
		//display fruit count
		
		GetComponent(TextMesh).text = blackberriesToDisplay.ToString();
		}
	else {
		//display total
		
		GetComponent(TextMesh).text = totalToDisplay.ToString();
		}
}

function UpdateBlackberries () {

	blackberries = targetScript.numBlackberries;
	total = targetScript.numTotal;
	divisor = 1;
	
	
	//find lowest form of fraction
	for (var i = blackberries; i > 0; i = i - 1) {
		if ((blackberries % i == 0) && (total % i == 0)){
			//common factor found
			divisor = i;
			i = 0;
		}
			
		
	}
	
	blackberriesToDisplay = blackberries / divisor;
	totalToDisplay = total / divisor;
	
	
}